<?php

class user_model extends CI_Model {

    public function __construct()
    {
       $this->load->database();
    }

    public function getWechatUser($open_id)
    {
        $result =  $this->db->get_where('user',['open_id'=>$open_id])->row_array();
        return $result;
    }
    public function getUser($user_id)
    {
        return $this->db->get_where('user',['user_id'=>$user_id])->row_array();
    }
    public function updateUser($user_id,$data)
    {
        $data = [
            'telephone' => $data['telephone'],
            'name' => $data['name']
        ];
        $this->db->update('user', $data, array('user_id' => $user_id));
    }
    public function insertUser($userinfo,$data)
    {
      if ($name) {
          $name -> $name;
        } else {
          $name -> $userinfo['nickName'];
        }
        $data = [
            'telephone'=>$data['telephone'],
            'name'=>$data['name'],
            'nick_name'=>$userinfo['nickName'],
            'gender'=>$userinfo['gender'],
            'language'=>$userinfo['language'],
            'city'=>$userinfo['city'],
            'province'=>$userinfo['province'],
            'country'=>$userinfo['country'],
            'avatar_url'=>$userinfo['avatarUrl'],
            'open_id'=>$userinfo['openId'],
            'date_added'=>date('Y-m-d H:i:s')
        ];
        $this->db->insert('user',$data);

        $data['user_id'] = $this->db->insert_id();

        return $data;
    }


}